import 'package:flutter/material.dart';
import 'package:getx/custom/customappbar.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:get/get.dart';

// ignore: must_be_immutable
class DialogGetX extends StatefulWidget {
  String name;
  DialogGetX({Key? key, required this.name}) : super(key: key);
  @override
  _DialogGetXState createState() => _DialogGetXState();
}

class _DialogGetXState extends State<DialogGetX> {
  void _snackbar() {
    Get.defaultDialog(
        title: 'Dialog 标题',
        titleStyle: TextStyle(color: Theme.of(context).primaryColor),
        content: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const [
            Text(
              '自定义content内容部分',
              style: TextStyle(
                fontSize: 20,
                color: Colors.white54,
              ),
            ),
            ListTile(
              leading: Icon(Icons.ac_unit), // 左侧图标按钮
              title: Text('标题'),
              subtitle: Text('副标题'),
              trailing: Icon(Icons.add), // 右侧图标按钮
            )
          ],
        ),
        textCancel: '取消',
        textConfirm: "确定",
        cancelTextColor: Theme.of(context).primaryColor,
        buttonColor: Theme.of(context).primaryColor,
        confirmTextColor: Colors.white,
        onConfirm: () {
          // ignore: avoid_print
          Get.back(); // 关闭弹窗
          // ignore: avoid_print
          print('确认按钮点击');
        },
        onCancel: () {
          // ignore: avoid_print
          print('取消按钮点击');
        },
        backgroundColor: Colors.white.withOpacity(0.8)
        // cancel: RaisedButton(
        //     onPressed: () {
        //       // ignore: avoid_print
        //       print('自定义取消按钮');
        //       Get.back(); // 关闭弹窗
        //     },
        //     child: const Text('取消'),
        //   ),
        // confirm: RaisedButton(
        //     onPressed: () {
        //       // ignore: avoid_print
        //       print('自定义确定按钮');
        //       Get.back(); // 关闭弹窗
        //     },
        //     child: const Text('确定'),
        //   ),
        );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            RaisedButton(
              onPressed: _snackbar,
              child: Text(widget.name),
            )
          ],
        ),
      ),
    );
  }
}
